from django.db import models
from django.contrib.auth.models import AbstractUser


# Create your models here.

class UserInfo(AbstractUser):
    # Type: 类型((0，学生)，(1，社团负责人)，(2，审核员))
    # Name: 姓名
    # Sex: 性别((0，女)，(1，男))
    # Email：邮箱
    # Phone: 电话
    id = models.AutoField(primary_key=True)
    password = models.CharField(max_length=128,null=True,default='pbkdf2_sha256$36000$fa9IoNVwGDfa$52WltgUtCKZTKmP5qlIcpDDMt3zEtAclXBob9abUVVw=')
    user_type_choose = ((0, '学生'), (1, '社团负责人'), (2, '审核员'))
    user_type = models.IntegerField(choices=user_type_choose, verbose_name='用户类型',default=0)
    name = models.CharField(max_length=12, verbose_name='姓名')
    sex_choose = ((0, '女'), (1, '男'))
    sex = models.IntegerField(choices=sex_choose,null=True,default=1)
    phone = models.CharField(max_length=32, null=True, blank=True, verbose_name='电话')

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = '用户'
        verbose_name_plural = verbose_name


class Usertoken(models.Model):
    user_obj = models.OneToOneField(to='UserInfo', related_name='token')
    token = models.CharField(max_length=64)


class Student(models.Model):
    # User_obj: 用户外键
    user_obj = models.OneToOneField(to='UserInfo', related_name='student')
    # Major: 所属专业
    major = models.CharField(max_length=32, verbose_name='所属专业')
    # stu_class: 所属班级
    stu_class = models.CharField(max_length=32, verbose_name='所属班级')
    # Club: 所属社团（可以为空）
    club = models.CharField(max_length=32, verbose_name='所属社团', null=True, blank=True)
    # Is_pic: 是否是负责人
    is_pl = models.BooleanField(verbose_name='是否负责人')

    def __str__(self):
        return self.user_obj.name

    class Meta:
        verbose_name = '学生'
        verbose_name_plural = verbose_name


class Club_Activities(models.Model):
    # Title: 活动主题
    title = models.CharField(max_length=64, verbose_name='活动主题')
    # Desc: 活动描述
    desc = models.CharField(max_length=256, verbose_name='活动描述')
    # act_starttime: 活动开始时间
    act_starttime = models.DateTimeField(verbose_name='活动开始时间')
    # act_endtime:活动结束时间
    act_endtime = models.DateTimeField(verbose_name='活动结束时间')
    # enroll_starttime: 报名开始时间
    enroll_starttime = models.DateTimeField(verbose_name='报名开始时间')
    # enroll_endtime: 报名截止时间
    enroll_endtime = models.DateTimeField(verbose_name='报名结束时间')
    # Now_Number: 目前报名人数，默认为0
    now_number = models.IntegerField(default=0, verbose_name='目前报名人数')
    # Max_number: 最大报名人数
    max_number = models.IntegerField(verbose_name='最大报名人数')
    # Place: 活动地点
    place = models.TextField(verbose_name='活动地点')
    # State: 活动状态((0, 审核中),(1, 审核通过))
    state_choose = ((0, '审核中'), (1, '审核通过'),(2, '审核失败'))
    state = models.IntegerField(choices=state_choose, verbose_name='活动状态',default=0)
    # false: 失败原因
    false = models.CharField(max_length=556, verbose_name='失败原因',null=True)
    # pl_obj: 负责人
    pl_obj = models.ForeignKey(to='Student', verbose_name='社团负责人', related_name='pl')
    # stu_obj:报名学生
    stu_obj = models.ManyToManyField(to='Student', verbose_name='报名学生', related_name='stu',blank=True)

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = '社团活动'
        verbose_name_plural = verbose_name
